(function() {
  require('./loadSnapshot');
  const path = require('path');

  if (typeof snapshotResult !== 'undefined') {
    snapshotResult.setGlobals(global, process, window, document, console, require, path.join(global.__dirname, '..'));
  }

  const querystring = snapshotResult.customRequire('querystring');
  const fp = snapshotResult.customRequire('lodash/fp');

  let loadSettings = {};
  const qs = querystring.parse(location.search.substr(1));
  if (qs.loadSettings) {
    loadSettings = JSON.parse(qs.loadSettings);
    // 个性化修改
    loadSettings.title = loadSettings.title + ' Pro'
    loadSettings.version = '106.5.1'
  }

  if (loadSettings && loadSettings.title) {
    document.title = loadSettings.title;
  }

  process.env.NODE_ENV = loadSettings.mode === 'development' ? 'development' : 'production';

  // This does not work unless it is mutable
  global.jasmine = window.jasmine;

  Object.defineProperty(window, 'loadSettings', {
    value: loadSettings,
    writable: false
  });

  // TODO fix this so that it can be turned into non-writable prop on global.
  // It is currently mutated in tests all willy nilly.
  global.mode = loadSettings.mode;

  Object.defineProperty(global, 'systemTest', {
    value: loadSettings.systemTest,
    writable: false
  });
  Object.defineProperty(global, 'unitTest', {
    value: loadSettings.unitTest,
    writable: false
  });
  Object.defineProperty(global, 'version', {
    value: loadSettings.version,
    writable: false
  });
  Object.defineProperty(global, 'clientType', {
    value: loadSettings.clientType,
    writable: false
  });
  Object.defineProperty(global, 'modePrefixString', {
    value: fp.cond([
      [fp.matchesProperty('mode', 'production'), () => ''],
      [fp.matchesProperty('systemTest', true), () => 'staging'],
      [fp.matchesProperty('mode', 'staging'), () => 'staging'],
      [fp.stubTrue, () => 'dev']
    ])(global),
    writable: false
  });
})();
